<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>rfft</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="rezzy.html" title="rezzy" />
    <link rel="next" href="rifft.html" title="rifft" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">rfft</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="rezzy.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="rifft.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="rfft"></a>
      <div class="titlepage"></div>
      <a id="IndexRfft" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">rfft</span>
        </h2>
        <p>rfft — 
      Fast Fourier Transform of a real-value array.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp143047200"></a>
        <h2>Description</h2>
        <p>
       Applies a forward Fast Fourier Transform to a real-value input 1-dimensional array. The output is another array 
containing the transform, non-redundant, non-negative spectrum only. If the input array is power-of-two, the output
array size will match the input size, with the first two points containing 0Hz and Nyquist frequency coefficients. Otherwise,
the output will have two extra values (input size + 2), and the the Nyquist coefficient will be placed at kin[input_size]
position (kin[1] and kin[input_size+1] will be 0]. 
    </p>
      </div>
      <div class="refsect1">
        <a id="idp143115744"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">kout[] <span class="command"><strong>rfft</strong></span> kin[]</pre>
      </div>
      <div class="refsect1">
        <a id="idp143117952"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>kout[]</em></span> -- output array containing the transform. It will be created if it does not exist.
         </p>
        <p>
      <span class="emphasis"><em>kin[]</em></span> -- input array containing the real-valued input.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp143120528"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the rfft opcode. It uses the file <a class="ulink" href="examples/rfft.csd" target="_top"><em class="citetitle">rfft.csd</em></a>.</p>
        <div class="example">
          <a id="idp143122480"></a>
          <p class="title">
            <strong>Example 765. Example of the rfft opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
-d -o dac
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>
<span class="comment">;ksmps needs to be an integer div of hopsize</span>
<span class="ohdr">ksmps</span> <span class="op">=</span> 64

<span class="oblock">instr</span> 1

 ihopsize <span class="op">=</span> 256   <span class="comment">; hopsize</span>
 ifftsize <span class="op">=</span> 1024  <span class="comment">; FFT size</span>
 iolaps <span class="op">=</span> ifftsize<span class="op">/</span>ihopsize <span class="comment">; overlaps</span>
 ibw <span class="op">=</span> <span class="ohdr">sr</span><span class="op">/</span>ifftsize <span class="comment">; bin bandwidth</span>
 kcnt <span class="opc">init</span> 0    <span class="comment">; counting vars</span>
 krow <span class="opc">init</span> 0

 kOla[] <span class="opc">init</span> ifftsize <span class="comment">; overlap-add buffer</span>
 kIn[] <span class="opc">init</span> ifftsize  <span class="comment">; input buffer</span>
 kSw[] <span class="opc">init</span> ifftsize
 kOut[][] <span class="opc">init</span> iolaps, ifftsize <span class="comment">; output buffers</span>

 a1 <span class="opc">diskin2</span> "fox.wav",1,0,1 <span class="comment">; audio input</span>
 ks  <span class="opc">expon</span>  100, p3, 1000
 asw <span class="opc">vco2</span>  <span class="opc">k</span>(a1), ks

 <span class="op">/</span><span class="op">*</span> every hopsize samples <span class="op">*</span><span class="op">/</span>
 <span class="octrl">if</span> kcnt <span class="op">==</span> ihopsize then
   <span class="op">/</span><span class="op">*</span> window and take FFT <span class="op">*</span><span class="op">/</span>
   kWin[] window kIn,krow<span class="op">*</span>ihopsize
   kSpec[] rfft kWin
   kWin window kSw,krow<span class="op">*</span>ihopsize
   kSpec2[] rfft kWin
   kProd[] cmplxprod kSpec, kSpec2

   <span class="op">/</span><span class="op">*</span> IFFT <span class="op">+</span> window <span class="op">*</span><span class="op">/</span>
   kRow[] rifft kProd
   kWin window kRow, krow<span class="op">*</span>ihopsize
   <span class="op">/</span><span class="op">*</span> place it on <span class="opc">out</span> buffer <span class="op">*</span><span class="op">/</span>
   kOut setrow kWin, krow

   <span class="op">/</span><span class="op">*</span> zero the ola buffer <span class="op">*</span><span class="op">/</span>
   kOla <span class="op">=</span> 0
   <span class="op">/</span><span class="op">*</span> overlap<span class="op">-</span>add <span class="op">*</span><span class="op">/</span>
   ki <span class="op">=</span> 0
   until ki <span class="op">==</span> iolaps do
     kRow getrow kOut, ki
     kOla <span class="op">=</span> kOla <span class="op">+</span> kRow
     ki <span class="op">+</span><span class="op">=</span> 1
   od

  <span class="op">/</span><span class="op">*</span> update counters <span class="op">*</span><span class="op">/</span>
  krow <span class="op">=</span> (krow<span class="op">+</span>1)<span class="op">%</span>iolaps
  kcnt <span class="op">=</span> 0
 <span class="octrl">endif</span>

 <span class="op">/</span><span class="op">*</span> shift audio <span class="opc">in</span><span class="op">/</span><span class="opc">out</span> of buffers <span class="op">*</span><span class="op">/</span>
 kIn shiftin a1
 kSw shiftin asw
 a2 shiftout kOla
    <span class="opc">out</span> a2<span class="op">/</span>iolaps

 <span class="op">/</span><span class="op">*</span> increment counter <span class="op">*</span><span class="op">/</span>
 kcnt <span class="op">+</span><span class="op">=</span> <span class="ohdr">ksmps</span>

<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span>1 0 10
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <br class="example-break" />
      </div>
      <div class="refsect1">
        <a id="idp143126640"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="vectorial.html" title="Vectorial Opcodes"><em class="citetitle"></em>Vectorial opcodes</a>,
      <a class="link" href="array.html" title="array"><em class="citetitle"></em>array</a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp143129648"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Victor Lazzarini</td>
          </tr>
          <tr>
            <td>NUI Maynooth</td>
          </tr>
          <tr>
            <td>2014</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in version 6.04</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="rezzy.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="rifft.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">rezzy </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> rifft</td>
        </tr>
      </table>
    </div>
  </body>
</html>
